home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / okimate20 / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1988-08-01  |  2.5 KB  |  108 lines

  1. /*
  2.     Transfer routine for Okimate_20.
  3.     David Berezowski - October/87.
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9. #include "../printer/prtgfx.h"
  10.  
  11. Transfer(PInfo, y, ptr, colors)
  12. struct PrtInfo *PInfo;
  13. UWORD y;    /* row # */
  14. UBYTE *ptr;    /* ptr to buffer */
  15. UWORD *colors; /* indexes to color buffers */
  16. {
  17.     extern struct PrinterData *PD;
  18.  
  19.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  20.     union colorEntry *ColorInt;
  21.     UBYTE *dmatrix, *yptr, *mptr, *cptr, y24, bit;
  22.     UBYTE dvalue, Yellow, Magenta, Cyan, threshold;
  23.     UWORD x, x3, width, sx, *sxptr;
  24.  
  25.     /* pre-compute */
  26.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  27.     x = PInfo->pi_xpos;
  28.     ColorInt = PInfo->pi_ColorInt;
  29.     sxptr = PInfo->pi_ScaleX;
  30.     width = PInfo->pi_width;
  31.     /* pre-compute ptr to dither matrix */
  32.     dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  33.  
  34.     /* printer specific */
  35.     bit = bit_table[y & 7];
  36.     y24 = (y % 24) >> 3;
  37.  
  38.  
  39.     if (PD->pd_Preferences.PrintShade == SHADE_COLOR) {
  40.         yptr = ptr + y24 + colors[0];
  41.         mptr = ptr + y24 + colors[1];
  42.         cptr = ptr + y24 + colors[2];
  43.         x3 = x * 3;
  44.         do { /* for all source pixels */
  45.             /* compute intensity values for each color component */
  46.             Yellow = ColorInt->colorByte[PCMYELLOW];
  47.             Magenta = ColorInt->colorByte[PCMMAGENTA];
  48.             Cyan = ColorInt->colorByte[PCMCYAN];
  49.             ColorInt++;
  50.  
  51.             sx = *sxptr++;
  52.  
  53.             do { /* use this pixel 'sx' times */
  54.                 dvalue = dmatrix[x & 3];
  55.                 if (Yellow > dvalue) {
  56.                     *(yptr + x3) |= bit;
  57.                 }
  58.                 if (Magenta > dvalue) {
  59.                     *(mptr + x3) |= bit;
  60.                 }
  61.                 if (Cyan > dvalue) {
  62.                     *(cptr + x3) |= bit;
  63.                 }
  64.                 ++x; /* done 1 more printer pixel */
  65.                 x3 += 3;
  66.             } while (--sx);
  67.         } while (--width);
  68.     }
  69.     else { /* b&w or grey_scale printout */
  70.         ptr += y24+ colors[0];
  71.         /* are we thresholding? */
  72.         if (threshold = PInfo->pi_threshold) {
  73.             /* yes, so pre-compute dither value */
  74.             dvalue = threshold ^ 15;
  75.             do { /* for all source pixels */
  76.                 Yellow = ColorInt->colorByte[PCMBLACK];
  77.                 ColorInt++;
  78.  
  79.                 sx = *sxptr++;
  80.  
  81.                 do { /* use this pixel 'sx' times */
  82.                     if (Yellow > dvalue) {
  83.                         *ptr |= bit;
  84.                     }
  85.                     ptr += 3;
  86.                 } while (--sx);
  87.             } while (--width);
  88.         }
  89.         else { /* greyscale */
  90.             do { /* for all source pixels */
  91.                 Yellow = ColorInt->colorByte[PCMBLACK];
  92.                 ColorInt++;
  93.  
  94.                 sx = *sxptr++;
  95.  
  96.                 do { /* use this pixel 'sx' times */
  97.                     dvalue = dmatrix[x & 3];
  98.                     if (Yellow > dvalue) {
  99.                         *ptr |= bit;
  100.                     }
  101.                     ptr += 3;
  102.                     ++x; /* done 1 more printer pixel */
  103.                 } while (--sx);
  104.             } while (--width);
  105.         }
  106.     }
  107. }
  108.